// hide loading gif

var loading_gif = function()
{
	if (
		document.getElementById('img')==null
		|| document.getElementById('form') == null
	)
	{
		window.setTimeout(loading_gif, 200);
		return;
	}
	document.getElementById('img').style.display='none';
	document.getElementById('form').style.visibility='';
};

window.setTimeout(loading_gif, 200);

dojo.addOnLoad( function()
{
	loadMenu();
	window.setInterval(loadMenu, 30000);
});

var loadMenu = function ()
{
	dojo.xhrGet({
		url: "?mdl=sidebar&action=read",
		handleAs: "json",
		load: function(data)
		{
			var html = "";
			if (data == null)
			{
				alert ("Time has expired. You have to activate etApps.");
			}
			for (var i=0; i<data.length; i++)
			{
				var width = "800";
				var data2 = data[i].split('|#|');
				if (data2[1] == "?mdl=admin" )
				{
					width = "900";
				}
				html += '<a href="'+ data2[1] +'" onclick="window.open(this.href, \'admin_'+i+'\', \'width='+width+',height=520\');return false;">'+data2[0]+'</a><br/>';
			}
			dojo.byId('menu').innerHTML = html;
		},
		error: function(response)
		{
			//alert ("Error: " + response);
		}
	});
};
